<template>
  <div>
    <Add ref="add" @ok="search"></Add>
    <Update ref="update" @ok="search"></Update>
    <ConfigurationAdd ref="ConfigurationAdd" @ok="search"></ConfigurationAdd>
    <ZgNewPage
      ref="page"
      title="推送任务配置"
      :showInlineBtn="false"
      :uniqueName="uniqueName"
      :pageOpt="pageOpt"
      :batchBtns="batchBtns"
      :dataBtns="dataBtns"
      :headers="headers"
      :conditions="conditions"
      @search="onSearch"
      @condition="onSearchWithCondition"
      @filter="onFilter"
      @header="mergeHeader"
      @admin="toAdmin"
      :extraBtns="extraBtns"
      @extra="toExtra"
    >
      <template slot="columns">
        <a-table-column
          v-for="(h, i) in headers"
          :key="`column${i}`"
          :width="h.width === 0 ? 'auto' : h.width"
          :title="h.label"
        >
          <template slot-scope="record">
            {{ record[h.code] }}
          </template>
        </a-table-column>
      </template>
      <template slot="thMode" slot-scope="scope">
        <a-row :gutter="10">
          <a-col :span="4" v-for="t in scope.list" :key="`thMode_${t.id}`">
            <a-card class="mb10">
              <div class="wfull h100 scroll">
                {{ t }}
              </div>
            </a-card>
          </a-col>
        </a-row>
      </template>
    </ZgNewPage>
  </div>
</template>
<script>
import Add from './Add'
import Update from './Update'
import ConfigurationAdd from './configurationAdd'
export default {
  components: {
    Add,
    Update,
    ConfigurationAdd
  },
  data () {
    return {
      uniqueName: 'test',
      pageOpt: {
        showConditionBtn: true,
        showHeaderConfig: true
      },
      headers: [
        { code: 'taskName', label: '任务名称', width: 150, isShow: true, sort: 0 },
        { code: 'taskName', label: '任务ID', width: 150, isShow: true, sort: 0 },
        { code: 'targetSystem', label: '目标系统', width: 120, isShow: true, sort: 0 },
        { code: 'jieKou', label: '目标接口', width: 120, isShow: true, sort: 0 },
        { code: 'miaShu', label: '描述', width: 220, isShow: true, sort: 0 },
        { code: 'age', label: '目标参数', width: 120, isShow: true, sort: 0 },
        { code: 'age', label: '目标数据库', width: 120, isShow: true, sort: 0 },
        { code: 'age', label: '目标表', width: 120, isShow: true, sort: 0 },
        { code: 'age', label: '数据选择逻辑', width: 120, isShow: true, sort: 0 },
        { code: 'age', label: '状态', width: 120, isShow: true, sort: 0 },
        { code: 'age', label: '创建人', width: 120, isShow: true, sort: 0 },
        { code: 'age', label: '创建时间', width: 120, isShow: true, sort: 0 }
      ],
      conditions: [
        { code: 'taskName', compType: '单行文本', label: '任务名称', defaultVal: '' },
        { code: 'targetSystem', compType: '下拉选择', label: '目标系统', defaultVal: '', extra: { 下拉选项: [{ value: '1', label: '虚拟仓' }, { value: '2', label: '交易' }] } },
        { code: 'jieKou', compType: '单行文本', label: '接口', defaultVal: '' }
        // { code: 'birth', compType: '日期区间', label: '生日', defaultVal: ['', ''] },
        // { code: 'age', compType: '整数区间', label: '年龄', defaultVal: [0, 100] },
        // { code: 'birth1', compType: '日期', label: '生日1', defaultVal: '2025-05-23' },
        // { code: 'age1', compType: '整数', label: '年龄1', defaultVal: 0 },
        // { code: 'name', compType: '单行文本', label: '姓名', defaultVal: '' },
        // { code: 'political', compType: '字典', label: '政治面貌', defaultVal: '', extra: { 字典类型: 'political' } },
        // { code: 'is_use', compType: '布尔', label: '启用1', defaultVal: 'false' },
        // { code: 'other1', compType: '单行文本', label: 'other1', defaultVal: '' },
        // { code: 'other2', compType: '单行文本', label: 'other2', defaultVal: '' },
        // { code: 'other4', compType: '单行文本', label: 'other4', defaultVal: '' },
        // { code: 'other5', compType: '单行文本', label: 'other5', defaultVal: '' },
        // { code: 'other6', compType: '单行文本', label: 'other6', defaultVal: '' },
        // { code: 'other7', compType: '单行文本', label: 'other7', defaultVal: '' }
      ],
      batchBtns: [
        // { key: 1, label: '批量删除' },
        // { key: 2, label: '批量修改' },
        // { key: 3, label: '数据排序' },
        // { key: 4, label: 'Excel导入' },
        // { key: 5, label: 'Excel导出' }
      ],
      dataBtns: [
        {
          key: 1,
          name: '删除',
          type: 'link',
          icon: 'fa-trash',
          isShow: () => {
            return true
          }
        },
        {
          key: 2,
          name: '修改',
          type: 'link',
          icon: 'fa-pencil',
          isShow: () => {
            return true
          }
        },
        {
          key: 3,
          name: '下架',
          type: 'link',
          icon: 'fa-file',
          isShow: () => {
            return true
          }
        },
        {
          key: 4,
          name: '运行记录',
          type: 'link',
          icon: 'fa-file-o',
          isShow: () => {
            return true
          }
        }
      ],
      extraBtns: [
        { key: 1, name: '新增任务', icon: 'plus-circle', type: 'primary' },
        { key: 2, name: '新增配置', icon: 'plus-circle', type: 'primary' }
      ]
    }
  },
  methods: {
    search () {
      this.$refs.page.search()
    },
    onSearch (param) {
      console.log(param, this.currentUser, '这是index.vue文件下,第144行,🤗🤔😤🤺')
      const diyHeaders = localStorage.getItem(this.currentUser.username + '_diyHeader_' + this.uniqueName)
      console.log(diyHeaders, '这是index.vue文件下,第146行,🤗🤔😤🤺')
      if (diyHeaders) {
        this.mergeHeader(JSON.parse(diyHeaders))
      }
      // 加载表头
      const list = [
        { key: '1', id: '1', taskName: '推送虚拟仓', targetSystem: '虚拟仓', jieKou: 'http://www.aaa.com', miaShu: '推送虚拟仓的', age: 18, isUse: true },
        { key: '2', id: '2', taskName: '推送中台', targetSystem: '中台', jieKou: 'http://www.bbb.com', miaShu: '推送中台的', age: 18, isUse: true },
        { key: '3', id: '3', taskName: '推送交易', targetSystem: '交易', jieKou: 'http://www.ccc.com', miaShu: '推送交易的', age: 18, isUse: true },
        { key: '4', id: '4', taskName: '推送结算', targetSystem: '结算', jieKou: 'http://www.ddd.com', miaShu: '推送结算的', age: 18, isUse: true },
        { key: '5', id: '5', taskName: '推送大屏', targetSystem: '大屏', jieKou: 'http://www.eee.com', miaShu: '推送大屏的', age: 18, isUse: true }
      ]
      this.$refs.page.endSearch({
        total: list.length,
        list: list
      })
    },
    onSearchWithCondition (condition) {
      // alert(condition)
    },
    onFilter (f, param) {},
    // 新增
    toExtra (opt) {
      console.log(opt, '这是index.vue文件下,第177行,🤗🤔😤🤺')
      if (opt.key === 1) {
        this.$refs.add.open()
      } else if (opt.key === 2) {
        this.$refs.ConfigurationAdd.open()
        console.log('新增配置', '这是indiv-pushTask 路径下名为 Index.vue的文件中的第 182 行🤺🤺🤺')
      }
    },
    // 操作
    toAdmin (param) {
      console.log(param, '这是index.vue文件下,第170行,🤗🤔😤🤺')
      if (param.key === 1) {
        this.confirm(() => {
          // this.$http.post('del-url', [param.obj.id], () => {
          //   this.search()
          // })
        }, '确定要删除这条数据么')
      } else if (param.key === 2) {
        this.$refs.update.open(param.obj)
      } else if (param.key === 3) {
        this.confirm(() => {
        }, '确定要下架么')
      } else if (param.key === 4) {
        this.$router.push({ path: '/indiv/pushLogs' })
      }
    },
    mergeHeader (newHeaders) {
      if (!newHeaders) {
        return
      }
      this.headers = newHeaders
        .filter((t) => {
          return t.isShow
        })
        .sort((a, b) => {
          return a.sort - b.sort
        })
    }
  }
}
</script>

<style lang="scss" scoped></style>
